package com.utils
{
	import  br.absolutobrasil.containers.com.adobe.Window;	
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;	
	import mx.controls.Alert;
	import mx.core.Application;
	import mx.events.CloseEvent;

	public class ControleWindow extends EventDispatcher
	{
		public function ControleWindow(target:IEventDispatcher=null)
		{
			super(target);
		}

		public static function criarWindow(objeto:Window,verifica:Boolean = false):*
		{
						if(verifica == false)
										{
											objeto = new  Window();
											mx.core.Application.application.addChild(objeto);
											objeto.isPopUp = true;
											objeto.addEventListener(CloseEvent.CLOSE, fechar);
											verifica = true;
										}else {
												if(!verifica)
												{	
																Alert.show("Janela já criada");
												}else{
																objeto = null;
												}
												verifica = false;
										}		
										
										return objeto;		
		}

		public static function fechar(event:CloseEvent):void
		{
								if(event.target.document)
								{
											//PopUpManager.removePopUp(event.currentTarget as IFlexDisplayObject);
											mx.core.Application.application.removeChild(event.target.document);
											event.target.document = null;
								}
		}

	}
}